﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_ManaShield : Buff, IDamageAbsorbBuff
    {
        private object lockObj = new object();

        override public void Resume(CreatureBase targetCreatureBase, SpellIcon _spellIcon, int timeRemaining, int castLevel, int castCharacterID, int castInt, int castWis, int optionalValue, string xmlData)
        {
            minutesLeft = timeRemaining;
            base.Resume(targetCreatureBase, _spellIcon, timeRemaining, castLevel, castCharacterID, castInt, castWis, optionalValue, xmlData);
            
            spellTimer.Start();
        }

        public int BuffPriority() { return 5; }
        public int AbsorbDamageReturnRemainder(int incomingMeleeDamage)
        {
            lock (lockObj)
            {

                if (incomingMeleeDamage >= TargetCreatureBase.Mana)
                {
                    this.RemoveSpell(true, true);
                    return incomingMeleeDamage - TargetCreatureBase.Mana;
                }
                else
                {
                    TargetCreatureBase.Mana = TargetCreatureBase.Mana - incomingMeleeDamage;
                    TargetCreatureBase.Update_Character();
                    return 0;
                }
            }
        }

        public Spell_ManaShield()
        {
            minutesLeft = 3;
        }
        public void Cast(CreatureBase myCreatureBase, int CastLevel, long CreatureGUID)
        {
            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCreatureBase, CastLevel, myCreatureBase.CreatureID, true, out MapItemsWithin12) == false)
                return;

            TargetCreatureBase.buffManager.UpdateBuffs();

            //Start Spell Timer
            spellTimer.Start();
        }
    }
}
